﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CuaHangMayTinh.Utilities;
using CuaHangMayTinh.DataProvider;
using CuaHangMayTinh.BusinessEntities;
using CuaHangMayTinh.DataAccessLayer;
using System.Data;

namespace CuaHangMayTinh.BusinessLogicLayer
{
    public class PhannQuyenManager
    {
        private static PhanQuyenDA adapter = null;

        static PhannQuyenManager()
        {
            if (adapter == null)
                adapter = new PhanQuyenDA();
        }


        /// <summary>
        /// Hàm thêm 1 Phân Quyền mới
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static int Insert(PhanQuyenEntity entity)
        {
            try
            {
                return adapter.Insert(entity);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return 0;
            }
        }

        /// <summary>
        /// Hàm Cập nhật 1 phân Quyền
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static bool UpDate(PhanQuyenEntity entity)
        {
            try
            {
                return adapter.UpDate(entity);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// Hàm tìm tất cả thông tin phân QUyền
        /// </summary>
        /// <returns></returns>
        public static DataTable Find_All()
        {
            try
            {
                return adapter.Find_All();
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// Hàm tìm phân quyền bằng IDSubGroupUser và  IDQuyen
        /// </summary>
        /// <param name="IDSubGroupUser"></param>
        /// <param name="Quyen"></param>
        /// <returns></returns>
        public static DataTable Find_SubGroupUser_Quyen(int IDSubGroupUser, int Quyen)
        {
            try
            {
                return adapter.Find_SubGroupUser_Quyen(IDSubGroupUser, Quyen);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// Hàm UpdateDiem
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static bool Update_Diem(PhanQuyenEntity entity)
        {
            try
            {
                return adapter.Update_Diem(entity);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// Hàm tìm phân quyền bằng ID Quyền và IDTaiKhoan
        /// </summary>
        /// <param name="IDSubGroupUser"></param>
        /// <param name="Quyen"></param>
        /// <returns></returns>
        public static DataTable Find_TaiKhoan_Quyen(int IDQuyen, int IDTaiKhoan)
        {
            try
            {
                return adapter.Find_TaiKhoan_Quyen(IDQuyen, IDTaiKhoan);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// Hàm tìm Phân Quyền bằng IDQuyen và ID Nhân Viên
        /// </summary>
        /// <param name="IDQuyen"></param>
        /// <param name="IDNhanVien"></param>
        /// <returns></returns>
        public static DataTable Find_NhanVien_Quyen(int IDQuyen, int IDNhanVien)
        {
            try
            {
                return adapter.Find_NhanVien_Quyen(IDQuyen, IDNhanVien);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }

        /// <summary>
        /// Hàm xóa 1 phân quyền
        /// </summary>
        /// <param name="IDQ"></param>
        /// <param name="IDSGU"></param>
        /// <returns></returns>
        public static bool Delete(int IDQ, int IDSGU)
        {
            try
            {
                return adapter.Delete(IDQ, IDSGU);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return false;
            }
        }

        /// <summary>
        /// Hàm chuyển 1 datatble thành 1 List PhanQuyenEntity
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public static List<PhanQuyenEntity> ConvertToList(DataTable dt)
        {
            try
            {
                return adapter.ConvertToList(dt);
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return null;
            }
        }
    }
}



